(function () {
    'use strict';

    angular
        .module('app.PatientDetails')
        .controller('PatientDetailsController', PatientDetailsController);

    PatientDetailsController.$inject = ['logger', '$state', '$rootScope', '$mdDialog'];
    /* @ngInject */
    function PatientDetailsController(logger, $state, $rootScope, $mdDialog) {
        var vm = this;
        vm.title = 'PatientDetails';
        vm.CloseDialog = CloseDialog;
        vm.SavePatientDetails = SavePatientDetails;

        activate();

        function activate() {
            logger.info('Activated PatientDetails View');
        }

        function CloseDialog(FormDirty) {
            if (FormDirty)
            {
                $mdDialog.show({
                    controller: 'ConfirmController',
                    skipHide: true,
                    preserveScope : true,
                    templateUrl: 'app/layout/ModalConfirm.html',
                    parent: angular.element(document.body),
                    controllerAs: 'vm',
                    clickOutsideToClose: false,
                    escapeToClose: false,
                    locals: {
                        ModalTitle: 'Confirm'
                        , ModalText: 'Changes have not been saved. Are you sure you want to cancel?'
                        , NoButtonText: 'No'
                        , YesButtonText: ' Yes'
                    }
                })
                .then(
                    //Yes Function
                    function () {
                        $mdDialog.cancel();
                    }

                    //No Function 
                    , function () {
                        //Do Nothing.
                    }
                );
            }
            else
            {
                $mdDialog.cancel();
            }
        }

        function SavePatientDetails() {
            $mdDialog.hide();
        }
    }
})();
